#ifndef DATATREE_H
#define DATATREE_H

#include <QTreeWidget>

 #include <App/Document.h>
 #include <App_Application.h>
 
 #include <Gui/DockWindow.h>
#include <Gui/Selection.h>

namespace Gui
{

	class ViewProviderDocumentObject;
	class DocumentObjectItem;
	class DocumentItem;
	class DataItem;

class DataTreeWidget : public QTreeWidget, public SelectionObserver
{
    Q_OBJECT

public:
    DataTreeWidget(/*Gui_Document* pDoc,*/QWidget* parent=0);
    ~DataTreeWidget();
public:

    void scrollItemToTop(Gui_Document*){}
    void setItemsSelected (const QList<QTreeWidgetItem *> items, bool select){}

protected:

	 int searchDataFile(const QString& sComFilePath,QTreeWidgetItem* wItem);
	/// Observer message from the Selection
	void onSelectionChanged(const SelectionChanges& msg);
	void contextMenuEvent (QContextMenuEvent * e);
	void drawRow(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
// 	bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data,
// 		Qt::DropAction action);
// 	Qt::DropActions supportedDropActions () const;
 	QMimeData * mimeData (const QList<QTreeWidgetItem *> items) const;
	//void dragMoveEvent(QDragMoveEvent *event);
// 	void dropEvent(QDropEvent *event);
//	void startDrag(Qt::DropActions supportedActions);
	void mouseDoubleClickEvent(QMouseEvent * event);

	//void startDrag(Qt::DropActions supportedActions);

protected Q_SLOTS:
    void onCreateGroup();
    void onRelabelObject();
    void onActivateDocument(QAction*);
    void onStartEditing();
    void onFinishEditing();

private Q_SLOTS:
    void onItemSelectionChanged(void);
    void onItemEntered(QTreeWidgetItem * item);
    void onTestStatus(void);

private:
   void traverseFile(QString path);
	void insetDataValue();

	void updataOutTreeData(QString path);

private:
	void slotNewDocument(const Gui_Document&);


private:
	QAction* createGroupAction;
	QAction* relabelObjectAction;
	QAction* finishEditingAction;
	QTreeWidgetItem* contextItem;

	QTreeWidgetItem* rootItem;
	QTimer* statusTimer;
	static QPixmap* documentPixmap;
	std::map<const Gui_Document*,DocumentItem*> DocumentMap;

	Gui_Document* activeDoc;

	std::vector<DataItem*> _dataItem;
	//std::map<std::string,DataItem*> _dataItems;
	//bool fromOutside;


    //void ShowFiles(int level, const QString &path);
};


class DataItem : public QTreeWidgetItem
{
public:
    DataItem(const Gui_Document* doc, QTreeWidgetItem * parent);
    ~DataItem();

public:

	void updataOutTreeData(QString path);
public:

    const Gui_Document* document() const;
    void setObjectHighlighted(const char*, bool);
    void setObjectSelected(const char*, bool);
    void clearSelection(void);
    void updateSelection(void);
    void selectItems(void);
    void testStatus(void);
    void setData(int column, int role, const QVariant & value);

protected:
    /** Adds a view provider to the document item.
     * If this view provider is already added nothing happens.
     */

    void slotNewObject(const Gui::ViewProviderDocumentObject&);
    /** Removes a view provider from the document item.
     * If this view provider is not added nothing happens.
     */
//     void slotDeleteObject(const Gui::ViewProviderDocumentObject&);
//     void slotChangeObject(const Gui::ViewProviderDocumentObject&);
//     void slotRenameObject(const Gui::ViewProviderDocumentObject&);
//     void slotActiveObject(const Gui::ViewProviderDocumentObject&);
//     void slotInEdit      (const Gui::ViewProviderDocumentObject&);
//     void slotResetEdit   (const Gui::ViewProviderDocumentObject&);

private:
    const Gui_Document* pDocument;
    std::map<std::string,DataItem*> ObjectMap;
};



}


#endif // DATATREE_H
